package org.example.controller;

import org.example.pojo.AdPosition;
import org.example.pojo.AdPositionVO;
import org.example.pojo.Result;
import org.example.service.AdPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.example.pojo.PageBean;

import java.util.List;

@RestController
@RequestMapping("/adposition")
public class AdPositionController {

    @Autowired
    private AdPositionService adPositionService;

    @PostMapping
    public Result add(@RequestBody @Validated AdPosition adPosition){
        adPositionService.add(adPosition);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(Integer id){
        adPositionService.delete(id);
        return Result.success();
    }

    @GetMapping
    public Result<PageBean<AdPosition>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) Integer clientId
    ){
        PageBean<AdPosition> pa = adPositionService.list(pageNum, pageSize, clientId);
        return Result.success(pa);
    }

    @GetMapping("/detail")
    public Result<AdPosition> detail(Integer id){
        AdPosition ad = adPositionService.detail(id);
        return Result.success(ad);
    }

    @PutMapping
    public Result update(@RequestBody @Validated AdPosition adPosition){
        adPositionService.update(adPosition);
        return Result.success();
    }

    @GetMapping("/test")
    public Result<PageBean<AdPositionVO>> getByClientName(
            Integer pageNum,
            Integer pageSize,
            @RequestParam String clientName){
        PageBean<AdPositionVO> adp = adPositionService.getByClientName(pageNum, pageSize, clientName);
        return Result.success(adp);
    }
}
